package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.util.JsonResult;
import cn.stylefeng.guns.sys.modular.system.entity.BtyShdkmx;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyMtsxfParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyShdkmxParam;
import cn.stylefeng.guns.sys.modular.system.service.BtyShdkmxService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


/**
 * 控制器
 *
 * @author liuy
 * @Date 2021-12-06 09:44:07
 */
@Controller
@RequestMapping("/btyShdkmx")
public class BtyShdkmxController extends BaseController {

    private String PREFIX = "/modular/system/btyShdkmx";

    @Autowired
    private BtyShdkmxService btyShdkmxService;

    /**
     * 跳转到主页面
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyShdkmx.html";
    }

    /**
     * 新增页面
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyShdkmx_add.html";
    }

    /**
     * 编辑页面
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyShdkmx_edit.html";
    }

    /**
     * 新增接口
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyShdkmxParam btyShdkmxParam) {
        this.btyShdkmxService.add(btyShdkmxParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyShdkmxParam btyShdkmxParam) {
        this.btyShdkmxService.update(btyShdkmxParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyShdkmxParam btyShdkmxParam) {
        this.btyShdkmxService.delete(btyShdkmxParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyShdkmxParam btyShdkmxParam) {
        BtyShdkmx detail = this.btyShdkmxService.getById(btyShdkmxParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author liuy
     * @Date 2021-12-06
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyShdkmxParam btyShdkmxParam) {
        return this.btyShdkmxService.findPageBySpec(btyShdkmxParam);
    }

    /**
     * 导入excel
     */
    @RequestMapping("/import")
    @ResponseBody
    public Object addUser(@RequestParam("file") MultipartFile file, BtyShdkmxParam shdkmxParam) {
        String fileName = file.getOriginalFilename();
        Boolean flag;
        JsonResult jsonResult = new JsonResult();
//        if(ToolUtil.isEmpty(shdkmxParam.getZdrq())){
//            jsonResult.setState(0);
//            jsonResult.setErrmsg("请先选择制单日期！");
//            return jsonResult;
//        }
        try {
            flag = btyShdkmxService.batchImport(fileName, file,shdkmxParam);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.setState(0);
            jsonResult.setErrmsg(e.getMessage());
            return jsonResult;
        }
        return flag;
    }

}


